package com.zr.util;
/**
 * 用于连接数据库的工具类
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JDBCUtil {
    private  static final String   DriverName = "com.mysql.jdbc.Driver";
    private  static final String   DBUrl = "jdbc:mysql://localhost:3306/stucs_sys?useUnicode=true&characterEncoding=UTF8";
    private  static final String   DBUname = "root";
    private  static final String   DBPsw = "123";
    /**
     * 获取数据连接
     * @return  返回Connection
     */
    public  static  Connection   getJDBConnection(){
    	  Connection  con = null;
    	  try {
			Class.forName(DriverName);
			con = DriverManager.getConnection(DBUrl, DBUname, DBPsw);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	  return  con;
    }
    /**
     * 关闭连接
     * @param con  传入需要关闭的连接
     */
    public  static  void closedConnection(Connection  con){
    	 if(con!=null){
    		 try {
				con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    	 }
    }
    
}
